package com.taint.advice;


import com.taint.callgraph.CallRecorder;
import com.taint.logger.TraceEntry;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.implementation.bytecode.assign.Assigner;

import java.lang.reflect.Method;

import static com.taint.logger.TraceEndpoint.ANNONEXIT;
import static com.taint.logger.TraceEndpoint.HTTPENTRY;


public class AnnotationAdvice {


    @Advice.OnMethodEnter
    public static TraceEntry MethodBefore(@Advice.This Object thised, @Advice.Origin Method method, @Advice.Origin("#t") String type, @Advice.Origin("#m") String methodName, @Advice.Origin("#d") String desc, @Advice.AllArguments Object[] args) {


        //System.out.println(Arrays.toString(method.getDeclaredAnnotations()));
        return CallRecorder.MethodBefore(HTTPENTRY, type, methodName, desc, args);

    }


    @Advice.OnMethodExit
    public static void MethodAfter(@Advice.Enter TraceEntry item, @Advice.Origin("#t") String type, @Advice.Origin("#m") String method, @Advice.Origin("#s") String sig, @Advice.Return(typing = Assigner.Typing.DYNAMIC, readOnly = false) Object returned) {

        CallRecorder.MethodAfter(ANNONEXIT, item,returned);
    }


}
